﻿using System.Web.Http;
using Ninject;
using System.Web.Mvc;
using TimberSmart.Business.Contracts;
using TimberSmart.Business;
using TimberSmart.Data.Contracts;
using TimberSmart.Data.Repositories;
using TimberSmart.Data;


namespace TimberSmart.Web
{
    public class IocConfig
    {
        public static void RegisterIoc(HttpConfiguration config)
        {
            var kernel = new StandardKernel();
            RegisterServices(kernel);

            // For Controllers
            DependencyResolver.SetResolver(
                t => kernel.TryGet(t),
                t => kernel.GetAll(t));

            // Tell WebApi how to use our Ninject IoC
            config.DependencyResolver = new NinjectDependencyResolver(kernel);
        }

        public static void RegisterServices(IKernel kernel)
        {
            kernel.Bind<IUserRepository>().To<UserRepository>();
            kernel.Bind<ITimberSmartUow>().To<TimberSmartUow>();
            kernel.Bind<IUserService>().To<UserService>();
        }
    }
}